package com.ruoyi.tcp.entity;

import com.ruoyi.tcp.util.TcpAesUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * @author 蒋翔 SY100242
 * @date 2024/8/7 15:22
 * @email SY100242@hnlens.com
 */
@Setter
@Getter
@ToString
public abstract class ClientCustomerBaseEntity extends CustomerBaseEntity {

    //数据发送时间
    protected LocalDateTime sendTime;

    public abstract byte[] getOtherBytesClient();

    public byte[] getSendTimeBytes() {
        Long sentTimeSecond = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
        sentTimeSecond=1615368542L;
        return TcpAesUtil.longToByteArray8(sentTimeSecond);
    }

    @Override
    public byte[] getOtherBytes() {
        byte[] sendTimeBytes = getSendTimeBytes();
        ByteBuf byteBuf = Unpooled.buffer().writeBytes(sendTimeBytes);
        byte[] otherBytesClient = getOtherBytesClient();
        byteBuf.writeBytes(otherBytesClient);
        return ByteBufUtil.getBytes(byteBuf);
    }
}
